#region Using References

using System;
using System.Diagnostics.Contracts;
using System.IO;

#endregion

namespace Beaker.Services.FileSystem.Physical
{
	internal sealed class File
		: IFile
	{
		private readonly FolderBase _parent;
		private readonly FileInfo _fileInfo;

		internal File( FolderBase parent, FileInfo fileInfo )
		{
			Contract.Requires<ArgumentNullException>( parent != null );
			Contract.Requires<ArgumentNullException>( fileInfo != null );

			_parent = parent;
			_fileInfo = fileInfo;
		}

		/// <summary>
		/// Gets the name of the entry
		/// </summary>
		public string Name
		{
			get { return _fileInfo.Name; }
		}

		/// <summary>
		/// Get the folder this entry is in
		/// </summary>
		public IFolder ParentFolder
		{
			get { return _parent; }
		}

		/// <summary>
		/// Open the file for reading
		/// </summary>
		/// <returns>A stream of the content of the file</returns>
		public Stream OpenRead()
		{
			return _fileInfo.OpenRead();
		}

		/// <summary>
		/// Open the text-file for reading
		/// </summary>
		/// <returns>A text-reader with the content of the file</returns>
		public TextReader OpenText()
		{
			return _fileInfo.OpenText();
		}
	}
}